﻿using System;
using System.Collections.Generic;
using Remind.Model;
using Remind.IDAL;
using Remind.AccessDAL;

namespace Remind.BLL
{
    public class UserBLL
    {
        private static readonly IUser dal = Remind.DALFactory.DataAccess.CreateUser();
        //查询当前记录条数
        public int GetUserCount()
        {
            return dal.GetUserCount();
        }

        /// <summary>
        /// 查询所有用户信息
        /// </summary>
        /// <returns></returns>
        public IList<UserInfo> GetUsers()
        {
            return dal.GetUsers();
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="uname">用户名</param>
        /// <param name="upwd">密码</param>
        /// <returns>登陆状态</returns>
        public UserInfo GetUserByUname(string uname)
        {
            return dal.GetUserByUName(uname);
        }

        /// <summary>
        /// 插入用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int InsertUser(UserInfo user)
        {   
            if (dal.GetUserByUName(user.Uname) != null)
                return 0;
            else
            {
                return dal.EditUser(user, Idu.insert);
            }
        }
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int EditUser(UserInfo user)
        {
            if (dal.GetUserByUName(user.Uname) != null)
            {
                return 0;//数据库中没有这个操作员信息
            }
            else
            {
                return dal.EditUser(user, Idu.update);
            }
        }
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int DelUser(UserInfo user)
        {
            
                return dal.EditUser(user, Idu.delete);
        }
    }
}
